<template>
  <j-modal
    :title="title"
    :width="600"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :rules="rules" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-form-model-item :wrapper-col="{ span: 24 }">
          {{ tipTxt }}
        </a-form-model-item>
        <a-form-model-item label="负样本标签" prop="labelName">
          <j-dict-select-tag v-model="form.labelName" placeholder="请选择" dictCode="sample_person_label" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
    <template slot="footer">
      <a-button key="back" @click="handleCancel">取消</a-button>
      <a-button key="submit" type="primary" @click="handleOk">确定</a-button>
    </template>
  </j-modal>
</template>

<script>
import * as peopleApi from '@/api/wxSmuggle/people.js'
export default {
  name: 'deleteModal',
  props: {
    title: {
      type: String,
      default: ''
    },
    tipTxt: {
      type: String,
      default: '确定将勾选的重点人转移到负样本人员库？'
    }
  },
  data() {
    return {
      rules: {
        labelName: [{ required: true, message: '请选择负样本标签' }]
      },
      visible: false,
      disableSubmit: false,
      form: {
        labelName: ''
      },
      labelCol: { span: 4 },
      wrapperCol: { span: 10 },
      confirmLoading: false,
      selectedKeys: null,
      idList: []
    }
  },
  computed: {},
  methods: {
    add() {
      this.visible = true
      this.$nextTick(() => {})
    },
    edit(record) {
      this.visible = true
      this.idList = record
      this.$nextTick(() => {})
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      let datas = []
      datas = JSON.parse(JSON.stringify(this.idList))
      datas.forEach((item, i) => {
        item.labelName = this.form.labelName
      })
      this.$refs.form.validate(valid => {
        if (valid) {
          peopleApi
            .wxFocusPersonDelete(datas)
            .then(res => {
              if (res.success) {
                this.$message.success(res.message)
                this.$emit('ok')
                this.form.labelName = ''
                this.handleCancel()
              } else {
                this.$message.warn(res.message)
              }
            })
            .catch(e => {
              this.$message.warn('请求失败！')
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>
<style lang="less" scoped></style>
